Component({
  properties: {
    ec: {
      type: Object,
      value: {}
    },
    canvasId: {
      type: String,
      value: ''
    }
  },
  data: {},
  lifetimes: {
    attached() {}
  },
  methods: {
    init(callback) {
      const query = this.createSelectorQuery()
      query.select('canvas').fields({ node: true, size: true }).exec((res) => {
        const canvas = res[0].node
        const width = res[0].width
        const height = res[0].height
        const dpr = wx.getWindowInfo ? wx.getWindowInfo().pixelRatio : wx.getSystemInfoSync().pixelRatio
        canvas.width = width * dpr
        canvas.height = height * dpr
        const ctx = canvas.getContext('2d')
        // 兼容 echarts 的 canvas API
        const echarts = require('./echarts')
        echarts.setCanvasCreator(() => canvas)
        callback(canvas, width, height, dpr)
      })
    }
  }
})


